<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>待阅事项</title>
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap-table.min.css" />
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>

<!-- 时间插件 -->
<script type="text/javascript" src="${_resources}datepicker/WdatePicker.js"></script>
<script type="text/javascript">
var readMessage;
var type = "${type}";
var numCode = "${numCode}";
$(function (){
	if(type == '1'){
		$("#updateMessageStatus").show(); 
		$("#confirm").hide(); 
		readTable();
		$("#readTable").removeClass("bbbb");
        $("#officeTable").removeClass("aaaa");
        $("#readTable").addClass("aaaa");
        $("#officeTable").addClass("bbbb");
	}else if(type == '0' || numCode !='tianjin712suo'){
		$("#officeTable").hide(); 
		$("#readTable").hide(); 
		$("#confirm").hide(); 
		readTable();
		$("#officeTable").addClass("aaaa");
        $("#readTable").addClass("bbbb");
        $("#officeTable").removeClass("bbbb");
        $("#readTable").removeClass("aaaa");
	}else{
		if(numCode =='tianjin712suo'){
			$("#updateMessageStatus").hide(); 
			 officeTable();
		}else{
			$("#officeTable").hide(); 
			$("#readTable").hide(); 
			$("#confirm").hide(); 
			readTable();
		}
		$("#officeTable").addClass("aaaa");
        $("#readTable").addClass("bbbb");
        $("#officeTable").removeClass("bbbb");
        $("#readTable").removeClass("aaaa");
	}
	 $("#officeTable").click(function(){
			var path='${_baseUrl}/index/showReadMessage';
			window.location.href=path;
	  });
	 $("#readTable").click(function(){
			var path='${_baseUrl}/index/showReadMessage?type=1';
			window.location.href=path;
	  });
})
function readTable(){
	readMessage = $("#readMessage").bootstrapTable({
		url : '${_baseUrl}/index/getReadMessageList',
		pagination: true,
		pageList: [5, 10, 20, 50,100,500],
  		queryParams: queryParams,
        columns: [{
			field: 'checked',
			checkbox: true,
			formatter : function(value, row, index) {
				if(row.messageStatus == "1"){
					return {
						disabled: true
	                };
				}
			}
	     },{
            field: 'messageId',
            title: 'messageId',
            visible:false,
            width: 5
        },{
            field: 'messageContent',
            title: '待阅事项内容',
            width: 400,
            formatter : function(value, row, index) {
            	if(row.messageStatus == "1"){
            		return "<span style='color:#C0C0C0'>"+value+"<span>";
            	}else{
            		return value;
            	}
            }
        },{
            field: 'createTime',
            title: '发送时间',
            width: 150,
            formatter : function(value, row, index) {
            	if(row.messageStatus == "1"){
            		return "<span style='color:#C0C0C0'>"+value+"<span>";
            	}else{
            		return value;
            	}
            }
        }]
    });
	
	function queryParams(params){
		var startTime = $("#startTime").val();
		var endTime = $("#endTime").val();
		return {
		    pageSize: params.limit,
		    pageNo: params.pn,
		    sort : params.sort,
		    order : params.order,
		    startTime : startTime,
		    endTime : endTime
	   }
	}
}

/* 标记为已读 */
function updateMessageStatus(){
	var selected = readMessage.bootstrapTable('getSelections');
	if(selected.length < 1){
		layer.msg("请选择要操作的数据");
		return false;
	}
	var messageIds = [];
	for(i=0;i<selected.length;i++){
		messageIds.push(selected[i].messageId);
	}
	$.ajax({
		url : "${_baseUrl}/index/updateMessageStatus",
		type : "post",
		dataType : "json",
		async : false,//** ！重要 同步请求。效果:ajax未进行则其他代码不运行
  		data : {messageId : messageIds.join(',')},
		success : function(json) {
			layer.msg(json.message);
			refreshTable();
			parent.skipModule("首页","");
		    parent.getUnreadMsg();
		},
		error:function(data){
			layer.msg("系统错误,请联系管理员");
		}
	});
};
function officeTable(){
	readMessage = $("#readMessage").bootstrapTable({
		url : '${_baseUrl}/index/getHandMessage',
		pagination: true,
		pageList: [5, 10, 20, 50,100,500],
  		queryParams: queryParams,
        columns: [{
			field: 'checked',
			checkbox: true,
	        formatter : function(value, row, index) {
	            	if("1" == row.messageStatus){
	            		return {disabled:true};
	            	}else
	            		return ;
	            }
	     },{
            field: 'messageId',
            title: 'messageId',
            visible:false,
            width: 5
        },{
            field: 'messageContent',
            title: '待办事项内容',
            width: 300,
            formatter : function(value, row, index) {
            	if(row.messageStatus == "1"){
            		return "<span style='color:#C0C0C0'>"+value+"<span>";
            	}else{
            		return value;
            	}
            }
        },{
            field: 'createTime',
            title: '发送时间',
            width: 150,
            formatter : function(value, row, index) {
            	if(row.messageStatus == "1"){
            		return "<span style='color:#C0C0C0'>"+value+"<span>";
            	}else{
            		return value;
            	}
            }
        },{
            field: 'handeTime',
            title: '确认时间',
            width: 150,
            formatter : function(value, row, index) {
            	if(row.messageStatus == "1"){
            		return "<span style='color:#C0C0C0'>"+value+"<span>";
            	}
            }
        }]
    });
	
	function queryParams(params){
		 var startTime = $("#startTime").val();
		var endTime = $("#endTime").val();
		return {
		    pageSize: params.limit,
		    pageNo: params.pn,
		    sort : params.sort,
		    order : params.order,
		    startTime : startTime,
		    endTime : endTime
	   } 
	}
}
function  confirm(){
	var selected = readMessage.bootstrapTable('getSelections');
	if(selected.length < 1){
		layer.msg("请选择要操作的数据");
		return false;
	}
	var messageIds = [];
	var userId = "" ;
	for(i=0;i<selected.length;i++){
		messageIds.push(selected[i].messageId);
		userId+=selected[i].projectId+",";
	}
	PwdResetMessage(userId);
	$.ajax({
		url : "${_baseUrl}/index/updateMessageStatus",
		type : "post",
		dataType : "json",
		async : false,//** ！重要 同步请求。效果:ajax未进行则其他代码不运行
  		data : {messageId : messageIds.join(',')},
		success : function(json) {
			layer.msg(json.message);
			refreshTable();
			//parent.skipModule("首页","");
		    //parent.getUnreadMsg();
		},
		error:function(data){
			layer.msg("系统错误,请联系管理员");
		}
	});
};
function PwdResetMessage(userId){
	 var path="${_baseUrl}/userController/PwdResetMessage";
	 $.ajax({    
		type: "POST",    
		async: false,    
		url:path,   
		data:{
			"userIds":userId ,
		},    
		success: function () {   
		} ,
		error:function(json){
			layer.msg("系统错误,请联系管理员");
		}  
	}); 
}

/* 关闭弹出框 */
function closeWin(){
	$("#popDiv").dialog('close');
}

function refreshTable(){
	readMessage.bootstrapTable('refresh');
}
</script>
<style type="text/css">
.to_do_list{width:8%;height:30px;line-height:30px;border: 1px solid #3979ff;float:left;text-align:center}
.to_be_read{width:8%;height:30px;line-height:30px;border: 1px solid #3979ff;float:left;text-align:center;margin-left: -1px;}
.surplus{width:83%;width: 83%;border-bottom: 1px solid #3979ff;float: left;height: 1px;margin-top: 29px;}
.aaaa{border-bottom:0}
.bbbb{border-top: 0;border-right: 0;}
</style>
</head>
<body style="overflow:hidden">
	<div class="" style="margin:10px auto">
     	<a href="javascript:;" class="fr blue_btn1" id="updateMessageStatus" onclick="updateMessageStatus()">标记为已阅</a>
     	<a href="javascript:;" class="fr blue_btn1" id="confirm" onclick="confirm()">确认</a>
  	
  	<c:if test="${numCode eq 'tianjin712suo' and userId eq 'safesecret'}">
  		<div class="func_time">
                <input id="startTime" type="text" placeholder="开始日期" onFocus="WdatePicker({startDate:'%y-%M-01',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})">
                <a href="javascript:void(0);" class="func_time_a"></a>
         </div>
         <div class="func_time">
                <input id="endTime" type="text" placeholder="结束日期" onFocus="WdatePicker({startDate:'%y-%M-01',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})">
                <a href="javascript:void(0);" class="func_time_b"></a>
         </div>
         <a class="blue_btn" href="javascript:refreshTable()">查询</a>
	    <div class="clear"></div>
    </c:if>
    </div>
      <div style="width:98%;margin: auto;">
 		   <table id="readMessage" class="table table-bordered table_inline" ></table>
     </div>      
</body>
<script type="text/javascript">
 $(".func_time_a").click(function(){
    	$("#startTime").focus();
    	});
    $(".func_time_b").click(function(){
    	$("#endTime").focus();
    	});
</script>
</html>